package com.yupi.tangoj.codebox.impl;

import com.yupi.tangoj.codebox.CodeSandBox;
import com.yupi.tangoj.codebox.SandBoxParam;
import com.yupi.tangoj.codebox.SandBoxVO;
import com.yupi.tangoj.common.ErrorCode;
import com.yupi.tangoj.exception.BusinessException;
import com.yupi.tangoj.model.dto.questionsubmit.JudgeInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.StringUtil;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

public class CodeSandBoxByCommon implements CodeSandBox {
    @Override
    public SandBoxVO executeCodeSandBox(SandBoxParam sandBoxParam) {

        System.out.println("常规 代码沙箱");
        SandBoxVO sandBoxVO = new SandBoxVO();

        String language = sandBoxParam.getLanguage();
        String code = sandBoxParam.getCode();
        List<String> input = sandBoxParam.getInput();

        //1.校验参数
        if (StringUtils.isAnyBlank(language,code) || input == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"参数异常");
        }
        //2.根据输入用例 执行用户代码


        //3.返回输出用例 判题信息
        JudgeInfo judgeInfo = new JudgeInfo();
        judgeInfo.setMessage("200 成功");

        sandBoxVO.setJudgeInfo(judgeInfo);

        List<String> outputList = Arrays.asList("1","2","3","4");
        sandBoxVO.setOutput(outputList);

        return sandBoxVO;
    }
}
